package cn.demo.day7;

import java.util.Arrays;

/**
 * 四格方块
 * 属性：
 * cells--四个方块
 * 行为：
 * moveLeft()--左移动
 * moveRight()--右移动
 * softDrop()--下落
 *
 * @author HP
 */
public class Tetromino {
    protected Cell[] cells = new Cell[4];

    public Cell[] getCells() {
        return cells;
    }

    public void setCells(Cell[] cells) {
        this.cells = cells;
    }

    public void moveLeft() {
        for (int i = 0; i < cells.length; i++) {
            cells[i].left();
        }
    }

    public void moveRight() {
        for (int i = 0; i < cells.length; i++) {
            cells[i].right();
        }
    }

    public void softDrop() {
        for (int i = 0; i < cells.length; i++) {
            cells[i].drop();
        }
    }

    @Override
    public String toString() {
        return "[" + Arrays.toString(cells) + "]";
    }

    /*
     * 随机生成一个四方块
     */
    public static Tetromino randomOne() {
        Tetromino t = null;
        int n = (int) (Math.random() * 7);
        switch (n) {
            case 0:
                t = new T();
                break;// 获取T类型，以下依次类推
            case 1:
                t = new I();
                break;
            case 2:
                t = new O();
                break;
            case 3:
                t = new S();
                break;
            case 4:
                t = new Z();
                break;
            case 5:
                t = new L();
                break;
            case 6:
                t = new J();
                break;
        }
        return t;
    }

    public class State {
        /*
         * 设置8个坐标
         * 分别存储四方块的不同状态下的位置
         */
        int row0, col0;
        int row1, col1;
        int row2, col2;
        int row3, col3;

        public State() {
        }

        public State(int row0, int col0, int row1, int col1, int row2, int col2, int row3, int col3) {
            super();
            this.row0 = row0;
            this.col0 = col0;
            this.row1 = row1;
            this.col1 = col1;
            this.row2 = row2;
            this.col2 = col2;
            this.row3 = row3;
            this.col3 = col3;
        }

    }
}
